package com.itheima.mall.dubbo.api.sms;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mall.commons.utils.StringUtils;
import com.itheima.mall.dubbo.mapper.sms.HomeRecommendSubjectMapper;
import com.itheima.mall.entity.domain.sms.HomeRecommendSubject;
import com.itheima.mall.entity.domain.vo.smsre.ResultAll;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class HomeRecommendSubjectServiceImpl extends ServiceImpl<HomeRecommendSubjectMapper, HomeRecommendSubject> implements HomeRecommendSubjectService {
    @Autowired
    private HomeRecommendSubjectMapper homeRecommendSubjectMapper;

    @Override
    public void updateSort(Long id, Integer sort) {
        HomeRecommendSubject homeRecommendSubject=new HomeRecommendSubject();
        homeRecommendSubject.setId(id);
        homeRecommendSubject.setSort(sort);
        homeRecommendSubjectMapper.updateById(homeRecommendSubject);
    }

    @Override
    public ResultAll page(Integer pageNum, Integer pageSize, Integer recommendStatus, String subjectName) {
        Page<HomeRecommendSubject> homeRecommendSubjectPage = new Page<>(pageNum, pageSize);
        ResultAll resultAll = new ResultAll();

        LambdaQueryWrapper<HomeRecommendSubject> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(subjectName), HomeRecommendSubject::getSubjectName, subjectName);
        queryWrapper.eq(recommendStatus != null, HomeRecommendSubject::getRecommendStatus, recommendStatus);

        homeRecommendSubjectMapper.selectPage(homeRecommendSubjectPage, queryWrapper);

        resultAll.setList(homeRecommendSubjectPage.getRecords());
        resultAll.setPageNum(pageNum);
        resultAll.setPageSize(pageSize);
        resultAll.setTotal(homeRecommendSubjectPage.getTotal());
        resultAll.setTotalPage(homeRecommendSubjectPage.getPages());
        return resultAll;





    }
}
